package com.anyou.mall.sho.controller;

import java.util.List;
import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;

import com.anyou.mall.sho.param.ShopNoticeParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.sho.domain.ShopNotice;
import com.anyou.mall.sho.service.IShopNoticeService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 商家通知信息Controller
 *
 * @author ruoyi
 * @date 2022-04-30
 */
@Api(tags = "商家通知信息")
@RestController
@RequestMapping("/shop/shopNotice")
public class ShopNoticeController extends BaseController
{
    @Autowired
    private IShopNoticeService shopNoticeService;

    /**
     * 查询商家通知信息列表
     * 需传商家id,carPartsShopId,登录时有返回
     */
    @ApiOperation("查询商家通知信息列表,需传商家id,carPartsShopId,登录时有返回,分页参数pageNum,pageSize")
    @PreAuthorize("@ss.hasPermi('shop:shopNotice:list')")
    @GetMapping("/list")
    public TableDataInfo<List<ShopNotice>> list(ShopNotice shopNotice)
    {
        startPage();
        List<ShopNotice> list = shopNoticeService.selectShopNoticeList(shopNotice);
        return getDataTable(list);
    }

//    /**
//     * 导出商家通知信息列表
//     */
//    @ApiOperation("导出商家通知信息列表")
//    @PreAuthorize("@ss.hasPermi('shop:shopNotice:export')")
//    @Log(title = "商家通知信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ShopNotice shopNotice)
//    {
//        List<ShopNotice> list = shopNoticeService.selectShopNoticeList(shopNotice);
//        ExcelUtil<ShopNotice> util = new ExcelUtil<ShopNotice>(ShopNotice.class);
//        util.exportExcel(response, list, "商家通知信息数据");
//    }

    /**
     * 获取商家通知信息详细信息
     */
    @ApiOperation("获取商家通知信息详情")
    @PreAuthorize("@ss.hasPermi('shop:shopNotice:query')")
    @GetMapping(value = "/{shopNoticeId}")
    public ApiResult<ShopNotice> getInfo(@PathVariable("shopNoticeId") Long shopNoticeId)
    {
        return ApiResult.success(shopNoticeService.selectShopNoticeByShopNoticeId(shopNoticeId));
    }

//    /**
//     * 新增商家通知信息
//     */
//    @ApiOperation("新增商家通知信息")
//    @PreAuthorize("@ss.hasPermi('shop:shopNotice:add')")
//    @Log(title = "商家通知信息", businessType = BusinessType.INSERT)
//    @PostMapping
//    public ApiResult add(@RequestBody ShopNotice shopNotice)
//    {
//        return ApiResult.success(shopNoticeService.insertShopNotice(shopNotice));
//    }

//    /**
//     * 修改商家通知信息
//     */
//    @ApiOperation("修改商家通知信息")
//    @PreAuthorize("@ss.hasPermi('shop:shopNotice:edit')")
//    @Log(title = "商家通知信息", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public ApiResult edit(@RequestBody ShopNotice shopNotice)
//    {
//        return ApiResult.success(shopNoticeService.updateShopNotice(shopNotice));
//    }

//    /**
//     * 删除商家通知信息
//     */
//    @ApiOperation("删除商家通知信息")
//    @PreAuthorize("@ss.hasPermi('shop:shopNotice:remove')")
//    @Log(title = "商家通知信息", businessType = BusinessType.DELETE)
//    @DeleteMapping("/{shopNoticeIds}")
//    public ApiResult remove(@PathVariable Long[] shopNoticeIds)
//    {
//        return ApiResult.success(shopNoticeService.deleteShopNoticeByShopNoticeIds(shopNoticeIds));
//    }

    /**
     * 商家通知设置已读
     */
    @ApiOperation("商家通知设置已读")
    @PreAuthorize("@ss.hasPermi('shop:shopNotice:isRead')")
    @PostMapping("/isRead")
    public ApiResult remove(@RequestBody ShopNoticeParam shopNoticeParam)
    {
        List<ShopNotice> list = shopNoticeService.list(new LambdaQueryWrapper<ShopNotice>()
                .in(ShopNotice::getShopNoticeId, shopNoticeParam.getShopNoticeIds()));
        list.forEach(shopNotice->{
            shopNotice.setIsRead(1);
        });
        shopNoticeService.updateBatchById(list);
        return ApiResult.success();
    }
}
